<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <script type="text/javascript" src="../internal.js"></script>
    <link rel="stylesheet" type="text/css" href="video.css" />
    <script src="https://simg.instrument.com.cn/JavaScript/jquery-1.7.1.min.js" type="text/javascript"></script>
    <style type="text/css">
        #videotable,
        #videotable tr th,
        #videotable tr td {
            border: 1px solid #f4f4f4;
            height: 40px;
            padding: 0 10px;
        }
    </style>
</head>

<body>

    <div>
        <table style="width:98%;margin:0 auto;">
            <tr>
                <!-- <td height="40">视频类别：<select name="VideoType" id="VideoType" style="width:200px;" onchange="videoTypeChangeFun(this.options[this.options.selectedIndex].value)" >
                    <option value="0">全部视频</option>
                    <option value="1">仪器介绍</option>
                    <option value="2">仪器操作</option>
                    <option value="3">公司介绍</option>
                    <option value="4">仪器应用</option>
                   <option value="5">资讯</option>
               </select></td> -->
                <td height="40"><input type="text" name="vkeywords" id="vkeywords" placeholder="请收入搜索关键词" />
                    <input type="button" value="搜索" onclick="VideoSearchFun()" />
                </td>
            </tr>
        </table>
        <table style="width:98%;margin:0 auto;" id="videotable">
            <tr style="text-align:left;background:#f4f4f4;height:40px;">
                <th>视频名称</th>
                <th>预览播放</th>
                <th>视频类别</th>
                <th>操作</th>
            </tr>
            <tbody id="videoTbody">

            </tbody>
        </table>
    </div>
    <!-- jquery -->
    <script type="text/javascript" src="../../third-party/jquery-1.10.2.min.js"></script>
    <!-- video -->
    <!--<script type="text/javascript" src="video.js"></script>-->
</body>

</html>
<script type="text/javascript">
    var videoAttr = [];
    //获取已存在是视频
    var videoobj = $("#UeditorNewsVideo", window.parent.document);
    var videos = videoobj.val();
    if (videos != undefined && videos != null && videos != "") {
        videoAttr = videos.split(",");
    }
    loadVideoList()
    // loadVideoList(0, "");
    // 2020-12-09 获取当前登录用户名
    function getCookie(cookie_name) {
        var allcookies = document.cookie;
        //索引长度，开始索引的位置
        var cookie_pos = allcookies.indexOf(cookie_name);

        // 如果找到了索引，就代表cookie存在,否则不存在
        if (cookie_pos != -1) {
            // 把cookie_pos放在值的开始，只要给值加1即可
            //计算取cookie值得开始索引，加的1为“=”
            cookie_pos = cookie_pos + cookie_name.length + 1;
            //计算取cookie值得结束索引
            var cookie_end = allcookies.indexOf(";", cookie_pos);

            if (cookie_end == -1) {
                cookie_end = allcookies.length;

            }
            //得到想要的cookie的值
            var value = unescape(allcookies.substring(cookie_pos, cookie_end));
        }
        return value;
    }

    //视频分类检索
    function videoTypeChangeFun(val) {
        loadVideoList(val, "");
    }
    //检索视频
    function VideoSearchFun() {
        var keyw = $("#vkeywords").val();
        loadVideoList(keyw);
    }
    //渲染视频列表
    function loadVideoList(keywords) {
        var userName = getCookie("locUserName");
        $.get("https://gateway.instrument.com.cn/member-portal-api/video/getFrameVideoListByImShowID", data = { "pageindex": 1, "limit": 100, "creator": userName, "keywords": keywords, "vstatus": 1,"imshowid":getCookie("imShowId") }, function (data) {
            var resData = data.data
            console.log(resData)
            var tbodytr = "";
            if (resData != null && resData != undefined && resData.length > 0) {
                for (var i = 0; i < resData.length; i++) {
                    switch (resData[i].videotype) {
                        case 1:
                            resData[i].videotype = '仪器介绍'
                            break;
                        case 2:
                            resData[i].videotype = '仪器操作'
                            break;
                        case 3:
                            resData[i].videotype = '公司介绍'
                            break;
                        case 4:
                            resData[i].videotype = '仪器应用'
                            break;
                        case 5:
                            resData[i].videotype = '资讯'
                            break;
                    }
                    tbodytr += "<tr>" +
                        "<td>" + resData[i].title + "</td>" +
                        "<td style=\"width:60px\"><a href=\"javascript:;\" onclick=\"OpenDialogAjax(this.href,'视频预览播放','" + resData[i].videoid + "');return false;\" class=\"alinkblue\">预览播放</a></td>" +
                        "<td>" + resData[i].videotype + "</td>" +
                        "<td style=\"width:50px\"><a href=\"javascript:void(0);\" onclick=\"SetVideoFun('" + resData[i].videoid + "')\">使用</a></td>" +
                        "</tr>";
                }
            } else {
                tbodytr = "<tr><td colspan=\"4\">您还没有视频，请前往视频中心上传视频。</td></tr>"
            }
            $("#videoTbody").html(tbodytr);
        });
    }
    /**
 * 监听确认和取消两个按钮事件，用户执行插入或者清空正在播放的视频实例操作
 */
    Array.prototype.contains = function (obj) {
        var index = this.length;
        while (index--) {
            if (this[index] === obj) {
                return true;
            }
        }
        return false;
    }
    //添加视频
    function SetVideoFun(vid) {
        editorcheckvideo();
        // if (videoAttr.length >0) {
        //     alert("每篇新闻只允许使用一个视频");
        // } else {
        //     videoAttr.push(vid);
        //     videoobj.val(videoAttr.join(","));
        //     dialog.onok(vid);
        //     dialog.close();
        // }
        videoAttr.push(vid);
        videoobj.val(videoAttr.join(","));
        dialog.onok(vid);
        dialog.close();
    }
    //检查编辑器中是否已存在视频
    function editorcheckvideo() {
        videoAttr = [];
        var content = editor.getContent();
        var regexvideo = /<img\s*.*?src=\\*\s*['\""]([^'\""]+)\s*.*?\s*vid=\\*\s*['\""]([^'\""]+)['\""][^>]*>/gi;
        if (content != undefined && content != null && content != "") {
            var videos = content.match(regexvideo);
            if (videos != null && videos.length > 0) {
                for (var i = 0; i < videos.length; i++) {
                    var regexVideoResult = videos[i].match(regexvideo);
                    var vid = RegExp.$2;
                    videoAttr.push(vid);
                }
            }
        }

    }
    dialog.onok = function (vid) {
        var videoimg = "<img src=\"https://img1.17img.cn/17img/images/202006/pic/8d5a061a-a569-47e4-ae0c-7582671d755f.jpg!w600x400.jpg\" vid=\"" + vid + "\">";
        editor.execCommand("inserthtml", "<p style=\"text-align:center;\">" + videoimg + "</p>");
    };
    //视频预览
    function OpenDialogAjax(url, title, videoid) {
        var parentbody = $("body", window.parent.document);
        var str = "<div style=\"position: fixed; z-index: 999999; left: 0;top: 0; width: 100%;height:100%;text-align:center;background: #333333;\" class=\"vpriwer\">" +
            "<span onclick=\"closeVideoPriwerFun($(this))\" style=\"background: #3987d9;color: #ffffff;width: 80px;display: inline-block; line-height: 40px;cursor: pointer;\">退出预览</span>" +
            "<div id=\"ccvideoboxid\" style=\"position: absolute;left: 50%;margin-left: -350px;top: 50%;margin-top: -250px;z-index: 9999999;color:#ffffff;\"></div></div>";
        parentbody.append(str);
        createscript(videoid);
    }
    //创建引用
    function createscript(vid) {
        var script = document.createElement("script");
        script.src = "https://p.bokecc.com/player?vid=" + vid + "&siteid=D9180EE599D5BD46&autoStart=true&width=700&height=500&playerid=D9180EE599D5BD46&playertype=1";
        script.type = "text/javascript";
        var t = window.parent.document.getElementById("ccvideoboxid");
        t.append(script)
        if (script.readyState) {   //IE
            script.onreadystatechange = function () {
                if (script.readyState == 'complete' || script.readyState == 'loaded') {
                    script.onreadystatechange = null;
                }
            }
        } else {    //非IE
            script.onload = function (e) {
            }
        }
    }
</script>